package cn.virens.oauth.subject;

import cn.virens.common.exception.APIException;
import cn.virens.oauth.request.principal.DelegatePrincipal;
import cn.virens.oauth.request.principal.DelegatePrincipalReadonly;
import cn.virens.oauth.service.AuthenticationService;

import java.io.Serializable;

@SuppressWarnings("serial")
public class SubjectSimple extends DelegatePrincipalReadonly implements Subject, Serializable {
    private final AuthenticationService mAuthenticationService;
    private final DelegatePrincipal mDelegatePrincipal;

    public SubjectSimple(AuthenticationService authentication, DelegatePrincipal principal) {
        this.mAuthenticationService = authentication;
        this.mDelegatePrincipal = principal;
    }

    @Override
    public boolean hasPermissions(String... permissions) throws APIException {
        return mAuthenticationService.hasPermissions(this, permissions);
    }

    @Override
    public boolean hasRoles(String... roleIdentifiers) throws APIException {
        return mAuthenticationService.hasRoles(this, roleIdentifiers);
    }

    @Override
    public DelegatePrincipal logout() throws APIException {
        return mAuthenticationService.logout(this);
    }

    @Override
    public DelegatePrincipal delegate() {
        return mDelegatePrincipal;
    }
}
